<script setup>
  import { onMounted, onUnmounted } from 'vue'
  import NavBar from '@/components/NavBar.vue'
  import AppMain from '@/components/AppMain.vue'
  import LoginDialog from '@/components/LoginDialog.vue'
  import RegisterDialog from '@/components/RegisterDialog.vue'
  import SigninDialog from '@/components/SigninDialog.vue'
  import useUserInfoStore  from '@/stores/userinfo'
  const userInfoStore = useUserInfoStore()
  let refreshTokenTimer = null
  
  const refreshToken = () => {
    if (userInfoStore.hasLogin) {
        // console.log('刷新token:', new Date())
        userInfoStore.refreshToken()
          .then(()=> {
            // 获取信息
            userInfoStore.getAppUserInfo()
          })
          // .catch(() => {
          // })
      }
  }
  onMounted(() => {
    refreshToken()
    refreshTokenTimer = setInterval(() => {
      refreshToken()
    }, 50 * 60 * 1000)
  })

  onUnmounted(() => {
    if(refreshTokenTimer) {
      clearInterval(refreshTokenTimer)
    }
  })

</script>
<template>
  <NavBar />
  <AppMain />
  <LoginDialog />
  <SigninDialog />
  <RegisterDialog />
</template>
